﻿package mortal.game.view.common.tooltip
{
    import com.mui.manager.*;
    import flash.display.*;
    import mortal.common.*;
    import mortal.game.view.common.tooltip.tooltips.*;

    public class Tooltip extends Sprite implements ItoolTipEntrance
    {
        public var left:DisplayObject;
        public var right:DisplayObject;
        protected var _factory:TooltipFactory;

        public function Tooltip()
        {
            return;
        }// end function

        public function set data(param1) : void
        {
            this.clear();
            if (this._factory == null)
            {
                this._factory = new TooltipFactory();
            }
            var _loc_2:* = this._factory.createToolTip(param1);
            if (_loc_2 == null)
            {
                return;
            }
            if (_loc_2.length >= 1)
            {
                this.left = _loc_2[0] as DisplayObject;
                if (this.left is Sprite)
                {
                    (this.left as Sprite).mouseEnabled = false;
                    (this.left as Sprite).mouseChildren = false;
                }
                this.addChild(this.left);
                if (this.left is IToolTipBaseItemComparable)
                {
                    (this.left as IToolTipBaseItemComparable).equiped = false;
                }
            }
            this.right = null;
            if (_loc_2.length >= 2)
            {
                this.right = _loc_2[1] as DisplayObject;
                this.addChild(this.right);
                this.right.x = this.left.width;
                if (this.right is Sprite)
                {
                    (this.right as Sprite).mouseEnabled = false;
                    (this.right as Sprite).mouseChildren = false;
                }
                if (this.right is IToolTipBaseItemComparable)
                {
                    (this.right as IToolTipBaseItemComparable).equiped = true;
                }
                if (this.left is IToolTipComparableWithUpDownArrow)
                {
                    (this.left as IToolTipComparableWithUpDownArrow).updateCombatUpDown((this.right as IToolTipComparableWithUpDownArrow).getMyCombat());
                }
            }
            this.leftShowMode = true;
            return;
        }// end function

        public function positionChanged() : void
        {
            if (this.left != null && this.left is ToolTipFuncPre_3D && this.left.parent != null)
            {
                (this.left as ToolTipFuncPre_3D).updatePosition();
                if (this.right != null && this.right is ToolTipFuncPre_3D && this.right.parent != null)
                {
                    (this.right as ToolTipFuncPre_3D).updatePosition();
                }
                return;
            }
            if (this.left != null && this.left is IToolTip3D && this.left.parent != null)
            {
                (this.left as IToolTip3D).updatePosition();
            }
            if (this.right != null && this.right is IToolTip3D && this.right.parent != null)
            {
                (this.right as IToolTip3D).updatePosition();
            }
            return;
        }// end function

        public function set leftShowMode(param1:Boolean) : void
        {
            if (this.left == null)
            {
                return;
            }
            this.left.x = 0;
            if (this.right == null)
            {
                return;
            }
            if (param1)
            {
                this.right.x = this.left.width;
            }
            else
            {
                this.right.x = 0;
                this.left.x = this.right.width;
            }
            return;
        }// end function

        protected function clear() : void
        {
            DisplayUtil.removeMe(this.left);
            DisplayUtil.removeMe(this.right);
            return;
        }// end function

        public function dispose() : void
        {
            return;
        }// end function

        override public function get width() : Number
        {
            var _loc_1:Number = 0;
            if (this.left && this.left.parent)
            {
                _loc_1 = _loc_1 + this.left.width;
            }
            if (this.right && this.right.parent)
            {
                _loc_1 = _loc_1 + this.right.width;
            }
            if (_loc_1 == 0)
            {
                _loc_1 = super.width;
            }
            return _loc_1;
        }// end function

        override public function get height() : Number
        {
            var _loc_1:Number = 0;
            var _loc_2:Number = 0;
            if (this.left && this.left.parent)
            {
                _loc_1 = this.left.height;
            }
            if (this.right && this.right.parent)
            {
                _loc_2 = this.right.height;
            }
            _loc_1 = Math.max(_loc_1, _loc_2);
            if (_loc_1 == 0)
            {
                _loc_1 = super.height;
            }
            return _loc_1;
        }// end function

    }
}
